package com.banshuibao.bsb_android.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.banshuibao.bsb_android.Constants;
import com.banshuibao.bsb_android.R;
import com.banshuibao.bsb_android.http.HttpResponse;
import com.banshuibao.bsb_android.http.HttpUtil;
import com.banshuibao.bsb_android.model.UserMessageModel;
import com.banshuibao.bsb_android.util.IntentManager;
import com.banshuibao.bsb_android.util.PriceUtil;

public class BalanceActivity extends BaseActivity implements View.OnClickListener {

    private ImageView back;
    private TextView balance;
    private RelativeLayout jyjl,tixian,txjl;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_balance);
        initView();
    }

    @Override
    protected void onResume() {
        super.onResume();
        getWallet();
    }

    private void initView() {
        back = findViewById(R.id.balance_back);
        balance = findViewById(R.id.balance_money);
        //提现
        tixian = findViewById(R.id.balance_relative_two);
        //交易记录
        jyjl = findViewById(R.id.balance_relative_three);
        //提现记录
        txjl = findViewById(R.id.balance_relative_four);
        back.setOnClickListener(this);
        jyjl.setOnClickListener(this);
        tixian.setOnClickListener(this);
        txjl.setOnClickListener(this);

//        float balance1 = GetLoginInfo.getLoginInfoInstance(this).readUser().getBalance();
//        balance.setText(String.valueOf(balance1));
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.balance_back:
                finish();
                break;
            case R.id.balance_relative_two:
                IntentManager.goWithdrawalsActivity(this);
                break;
            case R.id.balance_relative_three:
                IntentManager.goDealActivity(this);
                break;
            case R.id.balance_relative_four:
                IntentManager.goCashListActivity(this);
                break;
        }
    }

    //读取用户信息得到余额
    public void getWallet(){
        HttpUtil.doPost(Constants.Url.USER_MESSAGE, null, new HttpResponse(this,UserMessageModel.class) {
            @Override
            public void onResult(Object obj) {
                UserMessageModel messageModel = (UserMessageModel) obj;
                updateUserMessage(messageModel.getData());
            }
        });
    }

    void updateUserMessage(UserMessageModel.Data user) {
        double balance = user.getBalance();
        String price = PriceUtil.FormatDecimal(balance);
        this.balance.setText(price);
    }

}
